package com.heatup.apt.common.dao;


import com.baomidou.mybatisplus.mapper.AutoMapper;
import com.heatup.apt.model.api.course.CourseCoachTeamCampPrivateModel;
import com.heatup.apt.model.api.course.CourseDetailModel;
import com.heatup.apt.model.coach.CoachCourseInfo;
import com.heatup.apt.model.course.*;
import com.heatup.apt.model.course.CourseTime;
import com.heatup.apt.model.order.OrderPrivateUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface CourseInfoMapper extends AutoMapper<CourseInfo> {
//    int countByExample(CourseInfoExample example);

//    int deleteByExample(CourseInfoExample example);
//
//    @Delete({
//            "delete from course_info",
//            "where id = #{id,jdbcType=INTEGER}"
//    })
//    int deleteByPrimaryKey(Integer id);
//
//    @Insert({
//            "insert into course_info (id, course_standard_id, ",
//            "coach_count, crowd, ",
//            "course_attr, introduce, ",
//            "announcements, past_count, ",
//            "course_type, eval_lable, ",
//            "max_count, ",
//            "title, coach_comment, ",
//            "current_count, wait_count, ",
//            "status, created_by, ",
//            "created_time, updated_by, ",
//            "updated_time, version, ",
//            "min_count, periods, ",
//            "deadline, start_end_time, ",
//            "is_vip_used)",
//            "values (#{id,jdbcType=INTEGER}, #{courseStandardId,jdbcType=INTEGER}, ",
//            "#{coachCount,jdbcType=INTEGER}, #{crowd,jdbcType=VARCHAR}, ",
//            "#{courseAttr,jdbcType=VARCHAR}, #{introduce,jdbcType=VARCHAR}, ",
//            "#{announcements,jdbcType=VARCHAR}, #{pastCount,jdbcType=INTEGER}, ",
//            "#{courseType,jdbcType=VARCHAR}, #{evalLable,jdbcType=VARCHAR}, ",
//            "#{maxCount,jdbcType=INTEGER}, ",
//            "#{title,jdbcType=VARCHAR}, #{coachComment,jdbcType=VARCHAR}, ",
//            "#{currentCount,jdbcType=INTEGER}, #{waitCount,jdbcType=INTEGER}, ",
//            "#{status,jdbcType=CHAR}, #{createdBy,jdbcType=INTEGER}, ",
//            "#{createdTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=INTEGER}, ",
//            "#{updatedTime,jdbcType=TIMESTAMP}, #{version,jdbcType=INTEGER}, ",
//            "#{minCount,jdbcType=INTEGER}, #{periods,jdbcType=INTEGER}, ",
//            "#{deadline,jdbcType=TIMESTAMP}, #{startEndTime,jdbcType=VARCHAR}, ",
//            "#{isVipUsed,jdbcType=TINYINT})"
//    })
//    int insert(CourseInfo record);

//    int insertSelective(CourseInfo record);

//    List<CourseInfo> selectByExampleWithRowbounds(CourseInfoExample example, RowBounds rowBounds);

//    List<CourseInfo> selectByExample(CourseInfoExample example);
//
//    @Select({
//            "select",
//            "id, course_standard_id, coach_count, crowd, course_attr, introduce, announcements, ",
//            "past_count, course_type, eval_lable, head_img, max_count, title, coach_comment, ",
//            "current_count, wait_count, status, created_by, created_time, updated_by, updated_time, ",
//            "version, min_count, periods, deadline, start_end_time, is_vip_used, is_buy_one_class_limit",
//            "from course_info",
//            "where id = #{id,jdbcType=INTEGER}"
//    })
//    @ResultMap("BaseResultMap")
//    CourseInfo selectByPrimaryKey(Integer id);

    //查询课程详情列表，团课，私教，檬营，自助都是用的这个
    CourseInfo queryCourseInfoListById(Integer id);

//    int updateByExampleSelective(@Param("record") CourseInfo record, @Param("example") CourseInfoExample example);

//    int updateByExample(@Param("record") CourseInfo record, @Param("example") CourseInfoExample example);

//    int updateByPrimaryKeySelective(CourseInfo record);

    /**
     * 带版本控制更新课程
     *
     * @param record
     * @return
     */
    //int updateByPrimaryKeyAndVersionSelective(CourseInfo record);

//    @Update({
//            "update course_info",
//            "set course_standard_id = #{courseStandardId,jdbcType=INTEGER},",
//            "coach_count = #{coachCount,jdbcType=INTEGER},",
//            "crowd = #{crowd,jdbcType=VARCHAR},",
//            "course_attr = #{courseAttr,jdbcType=VARCHAR},",
//            "introduce = #{introduce,jdbcType=VARCHAR},",
//            "announcements = #{announcements,jdbcType=VARCHAR},",
//            "past_count = #{pastCount,jdbcType=INTEGER},",
//            "course_type = #{courseType,jdbcType=VARCHAR},",
//            "eval_lable = #{evalLable,jdbcType=VARCHAR},",
//            "max_count = #{maxCount,jdbcType=INTEGER},",
//            "title = #{title,jdbcType=VARCHAR},",
//            "coach_comment = #{coachComment,jdbcType=VARCHAR},",
//            "current_count = #{currentCount,jdbcType=INTEGER},",
//            "wait_count = #{waitCount,jdbcType=INTEGER},",
//            "status = #{status,jdbcType=CHAR},",
//            "created_by = #{createdBy,jdbcType=INTEGER},",
//            "created_time = #{createdTime,jdbcType=TIMESTAMP},",
//            "updated_by = #{updatedBy,jdbcType=INTEGER},",
//            "updated_time = #{updatedTime,jdbcType=TIMESTAMP},",
//            "version = #{version,jdbcType=INTEGER},",
//            "min_count = #{minCount,jdbcType=INTEGER},",
//            "periods = #{periods,jdbcType=INTEGER},",
//            "deadline = #{deadline,jdbcType=TIMESTAMP},",
//            "start_end_time = #{startEndTime,jdbcType=VARCHAR},",
//            "is_vip_used = #{isVipUsed,jdbcType=TINYINT}",
//            "where id = #{id,jdbcType=INTEGER}"
//    })
//    int updateByPrimaryKey(CourseInfo record);


    /**
     * 根据店面Id查询课程
     *
     * @param storeId
     * @return
     */
    List<CourseInfo> selectByStoreId(int storeId);

    /**
     * 获取门店列表
     * 这里的条件只是暂时加了 id 和 title 后续有需求在加
     *
     * @param map
     * @return
     */
    List<CourseInfo> getCourseList(Map<String, Object> map);

    /**
     * 查询檬营课程(分页)
     *
     * @param params
     * @return
     */
    List<CourseInfoModel> queryCourseList(Map<String, Object> params);

    /**
     * 查询檬营课程(总数)
     *
     * @param params
     * @return
     */
    int queryCourseCount(Map<String, Object> params);

    /**
     * 按主键查询檬营课程
     *
     * @param courseId
     * @return
     */
    CourseInfoModel queryCampCourseById(Integer courseId);

    /**
     * 查询团课
     *
     * @param params
     * @return
     */
    List<CourseTeamInfo> queryCourseTeamList(Map<String, Object> params);

    /**
     * 根据Id查询团课
     *
     * @param id
     * @return
     */
    CourseTeamInfo queryCourseTeamById(@Param("courseId") int id);


    CourseTeamResultModel queryCourseTeamResultById(@Param("courseId") int id);

    /**
     * 根据门店ID查询最新的2门团课
     *
     * @param id
     * @return
     */
    List<CourseInfo> queryLatestTeamCourseByStoreId(int id);

    /**
     * 查询檬营订单
     *
     * @param id
     * @return
     */
    int queryCourseOrderByCourseId(Integer id);

    int queryWaitCourseOrderByCourseId(Integer id);


    CourseInfo queryCourseInfoById(Integer id);

    /**
     * 根据服务ID查询檬营课程
     *
     * @param serviceId
     * @return
     */
//    @Select({
//            "SELECT ci.id, ci.course_standard_id, ci.coach_count, ci.crowd, ci.course_attr, ci.introduce, ci.announcements, ",
//            "ci.past_count, ci.course_type, ci.eval_lable, ci.head_img, ci.max_count, ci.title, ci.coach_comment, ",
//            "ci.current_count, ci.wait_count, ci.status, ci.created_by, ci.created_time, ci.updated_by, ci.updated_time, ",
//            "ci.version,  ci.min_count, ci.periods, ci.deadline, ci.start_end_time",
//            "FROM course_info AS ci",
//            "INNER JOIN service_price AS sp ON sp.course_id = ci.id",
//            "WHERE sp.id = #{serviceId}"
//    })
//    @ResultMap("BaseResultMap")
    CourseInfo queryCourseByServiceId(@Param("serviceId") Integer serviceId);

    /**
     * 教练端 团课列表
     *
     * @param paramsMap
     * @return
     */
    List<CourseCoachTeamCampPrivateModel> queryCoachTeamCourseListByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 团课列表总计
     *
     * @param paramsMap
     * @return
     */
    int queryCoachTeamCourseCountByMobile(Map<String, Object> paramsMap);
//
//    /**
//     * 教练端 团课累计课时
//     *
//     * @param paramsMap
//     * @return
//     */
//    int queryCoachTeamHadCourseCountByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 檬营列表 历史记录
     *
     * @param paramsMap
     * @return
     */
    List<CourseCoachTeamCampPrivateModel> queryCoachCampCourseHistoryListByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 檬营列表 历史总计
     *
     * @param paramsMap
     * @return
     */
    int queryCoachCampCourseHistoryCountByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 檬营列表
     *
     * @param paramsMap
     * @return
     */
    List<CourseCoachTeamCampPrivateModel> queryCoachCampCourseListByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 檬营列表总计
     *
     * @param paramsMap
     * @return
     */
    int queryCoachCampCourseCountByMobile(Map<String, Object> paramsMap);

    /**
     * 教练端 私教我的授课总计
     *
     * @param paramsMap
     * @return
     */
    int queryCoachPrivateCourseCount(Map<String, Object> paramsMap);

    /**
     * 教练端 私教列表 我的授课
     *
     * @param paramsMap
     * @return
     */
    List<CourseCoachTeamCampPrivateModel> queryCoachPrivateCourseList(Map<String, Object> paramsMap);

    /**
     * 教练端 私教 授课 总计
     *
     * @param paramsMap
     * @return
     */
    int queryCoachPrivateCourseHistoryCount(Map<String, Object> paramsMap);

    /**
     * 教练端 私教 授课记录
     *
     * @param paramsMap
     * @return
     */
    List<OrderPrivateUser> queryCoachPrivateCourseHistoryList(Map<String, Object> paramsMap);

    /**
     * 根据服务ID查询檬营课程
     *
     * @param orderId
     * @return
     */
    @Select({
            "SELECT oi.amount,sp.prime_price FROM order_info oi LEFT JOIN service_price sp ON oi.service_id = sp.id WHERE oi.id=#{orderId} "
    })
    Map<String, Object> getOrderInfo(@Param("orderId") Integer orderId);

    /**
     * 查询课程信息
     *
     * @param courseId 课程ID
     * @return
     */
    CourseInfoModel queryCourseByCourseId(Integer courseId);

    /**
     * API 查询课程信息(团课/私教/檬营)
     *
     * @param courseId 课程 ID
     * @return 课程信息
     */
    CourseDetailModel queryCourseById(Integer courseId);

    /**
     * 定时任务 查询90分钟内开课的课程信息列表
     */
    List<CoachCourseInfo> queryCoachCourseNotificationList();
    
    /**
     * 統計团课教练费用详情
     * @param param
     * @return
     */
    List<CoachFeeDetailVo> queryCoachFeeDetail(Map<String, Object> param);

    List<CourseInfoModel> getSecretExperienceAndPhysicalExaminationCourse();

    /**
     * 根据课程 ID 查询上课时间
     *
     * @param courseId   订单 ID
     * @return 课程开始时间 如果是檬营只返回 1正在上课 2已结束 如果私教不返回时间 团课/自助正常返回时间
     */
    CourseTime queryCourseStartTimeByCourseId(@Param("courseId") Integer courseId);

}